package com.itheima.sfbx.insurance.handler.impl;

import com.itheima.sfbx.framework.commons.constant.insure.InsureConstant;
import com.itheima.sfbx.insurance.dto.CustomerRelationVO;
import com.itheima.sfbx.insurance.dto.DoInsureVo;
import com.itheima.sfbx.insurance.handler.InsureHandler;
import com.itheima.sfbx.insurance.service.ICustomerRelationService;
import com.itheima.sfbx.insurance.service.impl.CustomerRelationServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName AccidentInsureHandler.java
 * @Description 保障型意外类：保险投保、创建订单、保费计算
 */
@Service
public class AccidentInsureHandler extends SafeguardInsureHandler implements InsureHandler {

/*- 在处理意外险保费计算的时候；提前对用户的收入进行判断
  - 月收入  高于100万或者没有填写的人直接抛出异常
  - 月收入 符合要求的则正常进行保费计算，保费计算直接沿用父类中方法即可*/

    @Autowired
    private ICustomerRelationService customerRelationService;

    @Override
    public String doPremium(DoInsureVo doInsureVo) {

        CustomerRelationVO relationVO = customerRelationService.findById(doInsureVo.getCustomerRelationIds().get(0));
        if(relationVO != null){
            BigDecimal income = relationVO.getIncome();
            if(income == null||income.compareTo(new BigDecimal(1000000)) > 0){
                throw new RuntimeException("杀手不能投意外险");
            }

        }

        return super.doPremium(doInsureVo);
    }
}
